package com.thyme.controller;

import com.thyme.domain.Blog;
import com.thyme.repository.BlogRepository;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author thyme
 * @ClassName BlogController
 * @Description TODO
 * @Date 2020/4/29 22:21
 */
@RestController
@RequestMapping("/blogs")
public class BlogController {


    @Autowired
    private BlogRepository blogRepository;


    @RequestMapping("/")
    public List<Blog> queryContent(@RequestParam(value = "key") String key) {
        List<Blog> blogList = new ArrayList<>();
        blogList.add(Blog.builder().content("人生若只如初见，何事秋风悲画扇。").build());
        blogList.add(Blog.builder().content("十年生死两茫茫，不思量，自难忘。").build());
        blogList.add(Blog.builder().content("曾经沧海难为水，除却巫山不是云。").build());
        blogList.add(Blog.builder().content("玲珑骰子安红豆，入骨相思知不知。").build());
        blogList.add(Blog.builder().content("只愿君心似我心，定不负相思意。").build());
        blogList.add(Blog.builder().content("去年今日此门中，人面桃花相映红。").build());
        blogList.add(Blog.builder().content("人面不知何处去，桃花依旧笑春风。").build());
        blogList.add(Blog.builder().content("疏影横斜水清浅，暗香浮动月黄昏。").build());
        blogList.add(Blog.builder().content("宁可枝头抱香死，何曾吹落北风中。").build());
        blogList.add(Blog.builder().content("人间四月芳菲尽，山寺桃花始盛开。").build());
        blogRepository.saveAll(blogList);
        return blogRepository.findByContentContains(key);
    }

}
